public class Text2 {
    //1089.复写0
    public void duplicateZeros(int[] arr) {
        int cur = 0, dest = -1;

        while(dest <= arr.length-1){
            if(arr[cur] != 0){
                dest++;
            } else {
                dest += 2;
            }

            if(dest >= arr.length - 1){
                break;
            }

            cur++;
        }

        if(dest == arr.length){
            arr[arr.length-1] = 0;
            dest -= 2;
            cur--;
        }

        while(cur >= 0){
            if(arr[cur] != 0){
                arr[dest--] = arr[cur--];
            } else {
                arr[dest--] = 0;
                arr[dest--] = 0;
                cur--;
            }
        }

    }
}
